import * as actionTypes from './constants';
import axios from 'axios';

const changeLogin = () => ({
  type: actionTypes.CHANGE_LOGIN,
  value: true,
});

export const login = (account, password) => {
  return (dispatch) => {
    axios
      .get('/api/login.json?account=' + account + '&password=' + password)
      .then((res) => {
        const result = res.data.data;
        if (result) {
          dispatch(changeLogin());
        } else {
          console.log('登录失败');
        }
        // dispatch(initHome(res.data.data.articleList, res.data.data.recommendList));
      })
      .catch((e) => {
        console.log(e);
      });
  };
};
